home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The X-Philes (2nd Revision)
/
The X-Philes Number 1 (1995).iso
/
xphiles
/
hp48_1
/
rn
< prev
next >
Wrap
Text File
|
1995-03-31
|
8KB
|
188 lines
Article 1938 of comp.sys.handhelds:
>From: AHDINW01@ulkyvx.BITNET
Newsgroups: comp.sys.handhelds
Subject: RN (v3.0) Smaller, faster, leaps small buildings...
Message-ID: <7A2C92B973FFE00F18@ulkyvx.bitnet>
Date: 18 Jun 90 07:27:00 GMT
Lines: 180
Hello Again,
I got some inspiration and time so here is RN (v3.0):
Quick Rerun:
RN (v1.0) - My version of RN not yet faster than Yoder's so Yoder's original
ROUN posted with some slight improvements.
RN (v2.0) - RN optimized little more, bug fixed and support of exponentials
added.
RN (v3.0) - My original RN version optimized and now faster than Yoder's in
addition to support of algebraics, tagged, and unit objects!
I have reverted back to my original method of rounding and optimized a
little bit. As a result, RN is now about 50 bytes smaller and much faster.
This version rounds 50 numbers(integers or floating points) in 8 to 9.3
seconds. The older version rounded 50 single digit integers fast (about 6
seconds), but the time increased with additional digits, taking up to 40 seconds
to round 50 floating point numbers!
RN is a program which given an object or composite structure will attempt
to correct all numbers appearing anywhere in the object that appear to be
perturbed due to calculator roundoff etc. RN round's up whenever 4 9's occur
a row in the mantissa of a number and round down when 4 0's occur. This can
easily be modified for more stricter or relaxed rounding by increasing or
decreasing the number of 0's or 9's.
* Note that my definition of what RN does is slightly different than that of
Yoder's original rounder. ie, I want to round ONLY numbers perturbed by the
calculator, therefore 5.39999999E-57 and 5.38953201E-57 will round to 5.4E-57
and 5.38953201E-57 respectively whereas Yoder's would return zero for both.
RN uses:
Given: 2.99999501 or (200.00053,-5.34999943E-34) or { 5 "Hi" 4.100002E50 }
Yields: 3 and (200 -5.3E-34) and { 5 "Hi" 4.1E50 }
Given : '2.0000001*X^2.23599999 + 7.3100000432'
Yields: '2*X^2.236 + 7.31'
Given : ANS: { 49.9992_ft '2-6.50400003E35*X' [ [ (1.00001,5) ] [ (2,3) ] ] }
Yields: ANS: { 50_ft '2-6.504E35*X' [ [ (1,5) ] [ (2,3) ] ] }
And so on...
As a side note:
This program does make use of the ^MATCH command, and I believe I am the
first to use it in a posted program (or at least in a non-table lookup
setting). Does anyone else have any clever uses for ^/vMATCH. I would be
interested in seeing them even if not their not incorporated in a program.
This command appears to have lots of hidden potential. For example, programs
using ^/vMATCH can be recursively called yielding obscure but interesting
results. People should be looking hard at this command.
Here's some food for thought:
If a binary tree is defined in the form, '((A+B)+C)+((D+E)+(F+(G+H))' where
'+' represents a node of the tree such as:
+
/ \
/ \
/ \
/ \
+ +
/ \ / \
/ \ / \
/ \ / \
+ C + +
/ \ / \ / \
A B D E F \
+
/ \
G H
then shouldn't it be possible to write routines to manipulate the tree using
^/vMATCH? Anybody want to comment?
BTW, if you do play around with ^/vMATCH, I suggest setting flag -53
(precedence flag) to display all parenthesis.
============================================================================
HP (if your listening), how about this for ^/vMATCH:
{ 'pattern' 'true replacement' ['false replacement'] ['conditional'] }
where 'pattern' is the subexpression for which to search, 'true/false
replacement' is the new subexpression, and 'conditional' specifies which
replacement is performed.
To facilitate the specification of the pattern, the 'pattern' and
'replacements' AND 'conditional' can contain "wildcard" names that will match
any subexpression. A wildcard variable is specified by prefixing any variable
name with the & character. I also want a wildcard operator variable (such
as % character) which will match any operator. Typical uses could be:
{ '&x %o &y' '&x %o &y' '&y - &x' 'condition' } or
{ '%o( &x )' 'SIN(&x)' 'COS(&x)' 'condition' }
and lastly, I want new functions (and old ones back):
EXGET, EXSUB, OBGET, OBSUB, etc...
LEVEL - given an algebraic, it returns the number of levels present, when used
in the 'condition' portion of the ^/vMATCH list it returns the current
level of its wildcard variable in the expression or a boolean value 1
if the current level matches the argument. Therefore:
Given : '((X+2)+Y)' LEVEL
Yields: 2
Given : { &x 'RN(&x)' '&x' 'LEVEL(&x) == LEVEL(3)' } ^/vMATCH
Yields: Replace &x with RN(&x) only for level 3 subexpressions.
Could this be implemented easily, doesn't look too tough too me (what do I
know) and would greatly enhance the calculator's usefulness! With not much
more effort this thing could be doing forward searches, back-tracking,
etc...(eeiioohh, I'm getting cold chills).
============================================================================
RN: Bytes #55BAh, 667 ; version 3.0
<< -> eq ; -> eq added so RN could be called
<< eq DUP -> TYPE t ; as a function. Now necessary!
<< CASE t NOT THEN
DUP SIGN SWAP DUP DUP
IF THEN XPON SWAP MANT END ; MANT doesn't like 0
->STR DUP "0000" POS ; Change "0000" as desired
IF DUP NOT
THEN DROP
ELSE 1 SWAP 1 - SUB
END
DUP "9999" POS ; Change "9999" as desired
IF DUP NOT
THEN DROP OBJ->
ELSE SWAP OBJ-> SWAP NEG RND
END
10 ROT ^ * *
END IF t 1 == ; Complex Number ?
THEN
C->R SWAP RN SWAP RN
IF DUP THEN R->C ELSE DROP END
END IF t 3 == t 4 == OR
THEN ; Real or Complex Array ?
OBJ-> DUP OBJ->
IF 2 == THEN * END
-> d s << 1 s START RN s ROLL NEXT d ->ARRY >>
END IF t 5 == ; List ?
THEN
OBJ-> -> s << 1 s START RN s ROLL NEXT s ->LIST >>
END IF t 9 == 1 ; Algebraic ?
tmp SAME NOT AND ; No points for beauty here!
THEN
1 'tmp' STO
{ &x 'RN(&x)' } ^MATCH ; Must use (UP)MATCH!
DROP EVAL
'tmp' PURGE
END IF t 12 == ; Tagged Object ?
THEN
OBJ-> SWAP RN SWAP ->TAG
END IF t 13 == ; Unit Object ?
THEN
OBJ-> SWAP RN SWAP _ ; _ is the underscore
END
END
>>
>>
>>
============================================================================
Aaron Dinwiddie
==> Agima <== ahdinw01@ulkyvx
How much is an out of warranty dead HP28S worth?
============================================================================